﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Xml.XPath;

namespace GaugeEngine.Behaviours
{
    public class Moveable : OnEventBehaviour
    {
        public Moveable(Actor a) : base(a)
        {
        }

        public override void Handler(Events.EventData eventData)
        {
            switch (eventData.ID)
            {
                case "KeyPress_Left":
                    {
                        ParentActor.Position.X -= 1.0f;
                        break;
                    }
                case "KeyPress_Right":
                    {
                        ParentActor.Position.X += 1.0f;
                        break;
                    }
            }
        }

        public static Behaviour CreateMoveable(Game g, Actor a, XPathNavigator xnav)
        {
            Moveable m = new Behaviours.Moveable(a);
            string events_to_listen_to = xnav.GetAttribute("listen_to", "");
            string[] events_array = events_to_listen_to.Split(',');
            foreach(string s in events_array) g.EventController.addHandler(s, m.Handler);
            return m;
        }
    }
}
